var map,mposctl,vectors, geojson,markers,selectControl;
var selectedFeature;
//Init
map = new OpenLayers.Map('floor4');
layer = new OpenLayers.Layer.Image(
    "floor4",
    "floor4.jpg",
    new OpenLayers.Bounds(-1105.5,-290,1105.5,290),
    new OpenLayers.Size(2211,580)
);
map.addLayer(layer);
map.zoomToMaxExtent();
var featurecollection = {
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_92",
            "properties": {
                "name": "A.402",
                "description": "Auditorium"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -1072,
                            256
                        ],
                        [
                            -794,
                            255
                        ],
                        [
                            -793,
                            39
                        ],
                        [
                            -1068,
                            38
                        ],
                        [
                            -1072,
                            256
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_114",
            "properties": {
                "name": "WC",
                "description": "Restroom"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -676,
                            255
                        ],
                        [
                            -556,
                            253
                        ],
                        [
                            -557,
                            65
                        ],
                        [
                            -676,
                            66
                        ],
                        [
                            -676,
                            255
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_138",
            "properties": {
                "name": "A.403",
                "description": "Auditorium"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -553,
                            254
                        ],
                        [
                            -373,
                            254
                        ],
                        [
                            -374,
                            67
                        ],
                        [
                            -551,
                            66
                        ],
                        [
                            -553,
                            254
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_160",
            "properties": {
                "name": "A.404",
                "description": "Auditorium"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -368,
                            253
                        ],
                        [
                            -190,
                            253
                        ],
                        [
                            -189,
                            65
                        ],
                        [
                            -368,
                            66
                        ],
                        [
                            -368,
                            253
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_184",
            "properties": {
                "name": "Biomedical engineering - Student Lab",
                "description": "lab room for BME students"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -182,
                            253
                        ],
                        [
                            7,
                            252
                        ],
                        [
                            6,
                            67
                        ],
                        [
                            -184,
                            65
                        ],
                        [
                            -182,
                            253
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_206",
            "properties": {
                "name": "A.406",
                "description": "Auditorium"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            12,
                            253
                        ],
                        [
                            190,
                            253
                        ],
                        [
                            191,
                            67
                        ],
                        [
                            12,
                            66
                        ],
                        [
                            12,
                            253
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_230",
            "properties": {
                "name": "A.407",
                "description": "Auditorium"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            195,
                            254
                        ],
                        [
                            386,
                            252
                        ],
                        [
                            388,
                            66
                        ],
                        [
                            194,
                            66
                        ],
                        [
                            195,
                            254
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_252",
            "properties": {
                "name": "A.408",
                "description": "Auditorium"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            391,
                            253
                        ],
                        [
                            576,
                            252
                        ],
                        [
                            575,
                            66
                        ],
                        [
                            392,
                            67
                        ],
                        [
                            391,
                            253
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_276",
            "properties": {
                "name": "WC",
                "description": "Restroom"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            581,
                            251
                        ],
                        [
                            677,
                            252
                        ],
                        [
                            680,
                            66
                        ],
                        [
                            582,
                            65
                        ],
                        [
                            581,
                            251
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_300",
            "properties": {
                "name": "A.409",
                "description": "Auditorium"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            841,
                            216
                        ],
                        [
                            1094,
                            217
                        ],
                        [
                            1093,
                            -176
                        ],
                        [
                            840,
                            -176
                        ],
                        [
                            841,
                            216
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_324",
            "properties": {
                "name": "Stair_4",
                "description": "Stair of Floor 4"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            678,
                            -185
                        ],
                        [
                            758,
                            -186
                        ],
                        [
                            757,
                            -257
                        ],
                        [
                            683,
                            -259
                        ],
                        [
                            678,
                            -185
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_350",
            "properties": {
                "name": "WC",
                "description": "Restroom"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            346,
                            -61
                        ],
                        [
                            528,
                            -60
                        ],
                        [
                            527,
                            -177
                        ],
                        [
                            348,
                            -177
                        ],
                        [
                            346,
                            -61
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_372",
            "properties": {
                "name": "Elevator_4",
                "description": "elevator of Floor 4"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            534,
                            -62
                        ],
                        [
                            679,
                            -61
                        ],
                        [
                            680,
                            -177
                        ],
                        [
                            535,
                            -177
                        ],
                        [
                            534,
                            -62
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_396",
            "properties": {
                "name": "Technical Services",
                "description": "supplying technical devices"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            117,
                            -61
                        ],
                        [
                            342,
                            -64
                        ],
                        [
                            342,
                            -170
                        ],
                        [
                            116,
                            -175
                        ],
                        [
                            117,
                            -61
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_418",
            "properties": {
                "name": "Biomedical Engineering Department - Prof Vo Van Toi office",
                "description": "personal office of Prof Vo Van Toi"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -109,
                            -61
                        ],
                        [
                            112,
                            -62
                        ],
                        [
                            110,
                            -175
                        ],
                        [
                            -110,
                            -176
                        ],
                        [
                            -109,
                            -61
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_442",
            "properties": {
                "name": "Department of Biomedical Engineering ",
                "description": "the working office of BME school"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -335,
                            -61
                        ],
                        [
                            -115,
                            -61
                        ],
                        [
                            -115,
                            -174
                        ],
                        [
                            -335,
                            -175
                        ],
                        [
                            -335,
                            -61
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_464",
            "properties": {
                "name": "A.413",
                "description": "Auditorium"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -532,
                            -60
                        ],
                        [
                            -341,
                            -61
                        ],
                        [
                            -340,
                            -175
                        ],
                        [
                            -532,
                            -176
                        ],
                        [
                            -532,
                            -60
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_486",
            "properties": {
                "name": "Elevator_4",
                "description": "elevator of Floor 4"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -677,
                            -61
                        ],
                        [
                            -539,
                            -61
                        ],
                        [
                            -538,
                            -176
                        ],
                        [
                            -681,
                            -178
                        ],
                        [
                            -677,
                            -61
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_510",
            "properties": {
                "name": "A.401",
                "description": "Auditorium"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -1068,
                            32
                        ],
                        [
                            -796,
                            32
                        ],
                        [
                            -797,
                            -179
                        ],
                        [
                            -1067,
                            -179
                        ],
                        [
                            -1068,
                            32
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_532",
            "properties": {
                "name": "Stair_4",
                "description": "Stair of Floor 4"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -746,
                            -187
                        ],
                        [
                            -686,
                            -188
                        ],
                        [
                            -686,
                            -256
                        ],
                        [
                            -745,
                            -257
                        ],
                        [
                            -746,
                            -187
                        ]
                    ]
                ]
            }
        }
    ]
}
geojson = new OpenLayers.Format.GeoJSON();
vectors = new OpenLayers.Layer.Vector();
selectControl= new OpenLayers.Control.SelectFeature(vectors,
    {onSelect: onFeatureSelect, onUnselect: onFeatureUnselect});
map.addLayer(vectors);
vectors.addFeatures(geojson.read(featurecollection));
map.addControl(selectControl);
selectControl.activate();
function onPopupClose(){selectControl.unselect(selectedFeature);};
function onFeatureSelect(feature){
    selectedFeature = feature;
    popup = new OpenLayers.Popup.FramedCloud(feature.id + "pop", feature.geometry.getBounds().getCenterLonLat(),null,"<div style='font-size:.8em'>Room: " + feature.attributes.name + "<br />Description: " + feature.attributes.description + "</div>",null, true, onPopupClose);
    feature.popup = popup;
    map.addPopup(popup);
}
function onFeatureUnselect(feature){
    map.removePopup(feature.popup);
    feature.popup.destroy();
    feature.popup = null;
}
